package com.woniuxy.mapper;


import com.work.framework.pojo.User;
import com.work.framework.pojo.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface Usermapper {
    /**
     * 根据用户id查用户
     * @param account
     * @return
     */

    @Select("Select * from user where account=#{account}")
    User FindUserByUseraccount(String account);

    /**
     *
     * @param user
     * @return
     */
    @Insert("insert into user (account,pwd) values(#{account},#{pwd})")
    @Options(useGeneratedKeys = true,keyProperty = "uid",keyColumn = "uid")
    Integer AddUser(User user);

    /**
     * 完善用户信息
     * @param userInfo
     * @return
     */
    @Insert("insert into user_info(username,phone,email,brithday,sex,uid,card)values(#{username},#{phone},#{email},#{brithday},#{sex},#{uid},#{card}")
    @Options(useGeneratedKeys = true,keyProperty = "uid",keyColumn = "uid")
    Integer AddUserMessage(UserInfo userInfo);

    /**
     *
     * @param phone
     * @return
     */
    @Insert("insert into user_info(phone) values(#{phone})")
    @Options(useGeneratedKeys = true,keyProperty = "uid",keyColumn = "uid")
    Integer AddPhone(String phone);

    /**
     * 通过uid查询用户详细信息
     * @param uid
     * @return
     */
    @Select("Select * from user_info where uid=#{uid}")
    List<UserInfo> findAll(Integer uid);

    /**
     * 通过uid查询用户信息
     * @param uid
     * @return
     */
    @Select("Select * from user where uid=#{uid}")
    User FindUserByUid(Integer uid);

    /**
     * 通过uid查询用户余额
     * @param uid
     * @return
     */
    @Select("Select amount from balance where uid=#{uid}")
    int FindMoneyByUid(Integer uid);

    /**
     * 通过uid找到用户详细信息
     * @param uid
     * @return
     */
    @Select("select * from user_info where uid= #{uid}")
    UserInfo FindUserMessageByUid(Integer uid);

    /**
     *
     * @return
     */
    @Select("SELECT * from user_info WHERE uid in(SELECT uid from user where r_id=1) ")
    List<UserInfo>findUsersInfo();

    /**
     *
     * @param userInfo
     * @return
     */
    @Update("update user_info set uname=#{uname},phone=#{phone},email=#{email},birthday=#{birthday},sex=#{sex} where uid=#{uid}")
    Integer changeMessage(UserInfo userInfo);

    @Update("update user set pwd=#{pwd} where uid=#{uid}")
    Integer ChangePwd(User user);
}
